package com.bit.blog.controller;

import com.bit.blog.pojo.request.UserLoginRequest;
import com.bit.blog.pojo.response.UserInfoResponse;
import com.bit.blog.pojo.response.UserLoginResponse;
import com.bit.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Resource(name="userServiceImpl")
    private UserService userService;
    @RequestMapping("/login")
    public UserLoginResponse login(@RequestBody @Validated UserLoginRequest userLoginRequest){
        //对用户和密码进行相关的校验；
        //使用相关组件进行验证：例如：@NotNull
        //在本类中需要进行使用@Validated进行声明，才可以发挥@NotNull的相关作用；
        log.info("用户登录，用户名："+userLoginRequest.getUserName());
        return userService.checkPassword(userLoginRequest);
    }
    //进行获取用户信息接口的设置‘；
    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull(message = "userId不能为空")Integer userId){
        log.info("进行获取用户相关的信息，userId"+userId);
        return userService.getUserInfo(userId);
    }
    //进行获取作者信息相关接口的设置；
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "blogId不能为空") Integer blogId){
        log.info("进行获取作者信息，blogId"+blogId);
        return userService.getAuthorInfo(blogId);
    }
 }
